[Fleet] Add namespace level customization for packages#262568
Conversation
83dbcb0 to
5047d41
Compare
5047d41 to
a8be4ae
Compare
|
Pinging @elastic/fleet (Team:Fleet) |
Catch flakiness early (recommended)Recommended before merge: run the flaky test runner against this PR to catch flakiness early. Trigger a run with the Flaky Test Runner UI or post this comment on the PR: This check is experimental. Share your feedback in the #appex-qa channel. Posted via Macroscope — Flaky Test Runner nudge |
|
/flaky ftrConfig:x-pack/platform/test/fleet_api_integration/config.space_awareness.ts:30 |
Flaky Test Runner✅ Build triggered - kibana-flaky-test-suite-runner#11659
|
ApprovabilityVerdict: Needs human review This PR introduces a new feature for namespace-level package customization, including new API endpoints, background tasks, and schema changes. Multiple unresolved review comments raise concerns about data integrity, performance, and error handling. The changes affect code owned by @elastic/fleet and require review by designated owners. You can customize Macroscope's approvability policy. Learn more. |
Flaky Test Runner Stats🎉 All tests passed! - kibana-flaky-test-suite-runner#11659[✅] x-pack/platform/test/fleet_api_integration/config.space_awareness.ts: 30/30 tests passed. |
|
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Page load bundle
History
|
|
@elasticmachine merge upstream |
vishaangelova
left a comment
There was a problem hiding this comment.
A couple of small suggestions, otherwise LGTM!
Co-authored-by: Visha Angelova <91186315+vishaangelova@users.noreply.github.com>
Co-authored-by: Visha Angelova <91186315+vishaangelova@users.noreply.github.com>
|
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Public APIs missing comments
Page load bundle
History
|
## Summary Closes #264065 This PR adds the following UI: * Input for managing namespaces enabled for customization for a given package in the package's Settings tab * Toggle for enabling/disabling a namespace for customization when creating/editing a package policy Note: release notes are included in #262568 ### Testing 1. Set up some allowed namespace prefixes for the space, e.g.: ``` PUT kbn:/api/fleet/space_settings { "allowed_namespace_prefixes": ["prod", "qa"] } ``` 2. Integration detail Settings tab * Pick an integration (e.g. System) * Check that the "Namespace customization" section is not rendered * Install the integration * The "Namespace customization" section should be rendered * Try to add a namespace that doesn't match the allowed prefixes (e.g. `staging`): it should be rejected * Add a namespace that matches the allowed prefixes (e.g. `prod1`): it should be allowed and a toast notification should confirm * Check that the namespace was correctly opted in via API (`GET /api/fleet/epm/packages/<pkg>`, `installationInfo.namespace_customization_enabled_for`) * Also test namespace opt out 3. Package policy editor (create flow) * Create a package policy (add the integration) * Open "Advanced options": there should be a toggle labelled "Enable namespace-level customization" that defaults to disabled * Add a namespace that matches the allowed prefixes and is not already opted in (e.g. `prod2`), enable the toggle: after saving the policy, this namespace should be added to the list of opted in namespaces for this package * Create another package policy with the same namespace (`prod2`), but this time leave the toggle disabled: there should be a warning that doing this will opt out the namespace, affecting the previously created package policy * Create another package policy with a namespace that is not opted in (e.g. `prod3`), leave the toggle disabled * Create another package policy with the same namespace (`prod3`) and enable the toggle: there should be a warning that doing this will opt in the namespace, affecting the previously created package policy 4. Package policy editor (edit flow) * For integration packages, it should be possible to change the namespace and whether it is opted in for the package * For input packages, the namespace cannot be changed after creation but it should be possible to change whether it is opted in for the package ### Screenshots <img width="1917" height="878" alt="Screenshot 2026-05-13 at 15 52 26" src="https://github.com/user-attachments/assets/7b667f02-6fc4-4148-8b96-b665fc67a9b4" /> <img width="1917" height="826" alt="Screenshot 2026-05-13 at 15 53 19" src="https://github.com/user-attachments/assets/d7b4a969-3911-4b77-8f96-d52b982f0f3b" /> <img width="1917" height="671" alt="Screenshot 2026-05-13 at 15 55 11" src="https://github.com/user-attachments/assets/9373c64b-f7ce-4a4f-bf51-db0805214aca" /> <img width="1917" height="666" alt="Screenshot 2026-05-13 at 15 55 36" src="https://github.com/user-attachments/assets/d0f45b43-ee21-407c-beb0-396cf1880405" /> <img width="1917" height="666" alt="Screenshot 2026-05-13 at 15 56 02" src="https://github.com/user-attachments/assets/ba040ef0-2cde-415e-a4ba-347bcdadc7c7" /> ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Summary
Closes #245181
Fleet currently supports user customization at the type level (e.g.
logs@custom) and data-stream level (e.g.logs-system.application@custom), but not at the namespace level. Users managing multiple integrations under a shared namespace must configure each data stream individually.This PR implements namespace level customization by adding opt-in per-namespace index templates.
This is an API-only solution for now. #264065 will implement UI changes.
Solution rationale
Fleet currently creates one base index template per data stream pattern defined by the integration, e.g.
logs-system.application-*. This index templates applies to all matching data streams regardless of namespace, e.g.logs-system.application-productionandlogs-system.application-staging). This means that namespace-specific component templates (e.g.production@customandstaging@custom) cannot belong to that index template, otherwise they would compete with each other and affect all data streams, not just the relevant namespace.In this change, Fleet creates a dedicated index template per data stream with a more specific index pattern and higher priority than the base template. This namespace template is a clone of the base template with
{namespace}@customadded tocomposed_of. The base template is never modified.Example:
Component templates in
logs-system.application:Component templates in
logs-system.application@namespace.production:Opt-in mechanism
Creating namespace templates for every namespace by default could potentially cause many templates to be created unnecessarily. To mitigate this, namespace level customization is opt-in and managed in the package installation:
Namespaces can be opted in by updating the package installation:
Or using the new bulk API:
Space awareness
Installation saved objects are shared across spaces, meaning the list of opted in namespaces for an installed package is cluster wide: any Kibana space that can see an integration sees the same opt-in list. Index templates and component templates are also cluster wide.
The present implementation attempts to mitigate the write-side of this using the
allowed_namespace_prefixesper-space restriction mechanism in Fleet settings (which is already used to gate which namespaces a user can choose for agent/package policies in a given space).When the user attempts to modify the list of opted in namespaces, it will be validated against allowed namespace prefixes if any (if none are set, there's no validation). For example, if
prodnamespace is allowed in space A, then from that spaceprod_euandprod_uswould be allowed, but notqa.Performance and scaling
Namespace template creation and deletion is handled by an asynchronous task. This addresses risks of latency/timeouts and provides a built-in retry mechanism.
Testing
Per-package opt-in creates namespace templates (existing policies)
Install the System integration with a package policy using namespace
production.Verify no namespace template exists yet:
should return 404.
production:In particular, check:
index_patternsis["logs-system.application-production*"]priorityis 250composed_ofincludesproduction@customNamespace template shows in Assets tab
In Kibana UI → Integrations → System → Assets tab, confirm
logs-system.application@namespace.production(and any other per-dataset variants) appear alongside other Fleet-managed assets.Namespace component templates are applied to their specific data streams only
production@customcomponent template, e.g.:This should create the data stream and its first backing index automatically, using the
logs-system.application@namespace.productionindex template (priority 250) rather than the baselogs-system.application template(priority 200).3. Verify the
productionnamespace data stream hasnumber_of_replicas: 2:number_of_replicas: 2, confirming namespace isolation.Opt-out deletes index templates but keeps component templates
production:production@customcomponent template still exists.Uninstall cleans up namespace templates
productionback in, namespace index template should exist.Bulk endpoint
productionandstagingnamespaces for both:enableanddisable.enableanddisable:Space awareness
Should result in:
prod_eu), it should work.stagingand try to opt outprod_eu(pass an empty array): it should reject withCannot change namespace customization for: prod_eu. Allowed prefixes in this space: staging.Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesbackport:*labels.Identify risks
Risk of eventual consistency gap if package installation SO is saved (synchronous) but the async task fails to create/delete index templates.
Release note
Add opt-in namespace level customization to integrations.